$(function(){
	/**********滑动菜单*******************/
    $(".li_bg").css("width","34px");
    var oUl = $(".nav");
    var aLi = $(".nav li");
    var oBg = aLi[aLi.length - 1];
    for(var i = 0; i < aLi.length - 1; i++){
       $(".li_bg").css("left",aLi[1].offsetLeft+20);
        aLi[i].onmouseover = function(){
            $(".li_bg").css("width",$(this).width());
            startMove(oBg, this.offsetLeft+5);
        }
    }
    var iSpeed = 0;
    //声明一个中间变量
    var left = 0;
    function startMove(obj, iTarget){
        clearInterval(obj.timer);
        obj.timer = setInterval(function(){
            //0.7  5
            iSpeed += (iTarget - obj.offsetLeft) / 5;
            iSpeed *= 0.7;
            //将误差减小的1以内
            left += iSpeed;
            //【注】为了节省资源,运动到位置后,需要关闭定时器
            //1>速度为0
            //2>到达目标值    当两个条件都成立的时候,可以关闭定时器
            if(Math.abs(iSpeed) < 1 && Math.abs(left - iTarget) < 1){
                clearInterval(obj.timer);
                //当运动结束后,挪到目标位置
                obj.style.left = iTarget + "px";
            }else{
                obj.style.left = left + "px";
            }
            //最后停止的位置有误差
            //iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.ceil(iSpeed);
            //document.title = obj.offsetLeft + "," + iSpeed;
        }, 30);
    }
     //回到顶部
          //当点击跳转链接后，回到页面顶部位置
          $("#back-to-top").click(function() {
            $('body,html').animate({
              scrollTop: 0
            },
            1000);
            return false;
          });
         /* 热线电话*/
         $(".telphone").mouseover(function(){
            $(".tel").css("display","block")
         });
         $(".telphone").mouseout(function(){
            $(".tel").css("display","none")
         })
          /* 微信*/
          $(".weixin").mouseover(function(){
            $(".wx").css("display","block")
         });
         $(".weixin").mouseout(function(){
            $(".wx").css("display","none")
         })

         /**********************banner图********************/
         var mySwiper = new Swiper ('.banner .swiper-container', {
            onInit: function(swiper){ //Swiper2.x的初始化是onFirstInit
              swiperAnimateCache(swiper); //隐藏动画元素 
              swiperAnimate(swiper); //初始化完成开始动画
            }, 
            onSlideChangeEnd: function(swiper){ 
              swiperAnimate(swiper); //每个slide切换结束时也运行当前slide动画
            } 
            })  

  /**********************弹出框********************/
   $("#add").click(function(){
    $('body,html').animate({
              scrollTop: 0
            },
            1000);
    var node = document.getElementById("img");
    var disX= 0;
    var disY = 0;
    var preX =0;
    var preY = 0;
    var iSpeedX = 0;
    var iSpeedY = 0;
    var timer = null;
    node.style.width = 0;
    node.style.height=0;
    node.style.left = document.documentElement.clientWidth/2+"px";
    node.style.top =document.documentElement.clientHeight/2+"px";
    toChange(350);
    function toChange(iTarget){
      var offsetL = node.offsetLeft;
      var offsetT = node.offsetTop;
      var timer = setInterval(function(){
        if(node.offsetWidth == iTarget){
          clearInterval(timer)
        }else{
          node.style.width = node.offsetWidth + 10 +"px";
          node.style.height=node.offsetHeight + 10 +"px";
          node.style.left = offsetL - node.offsetWidth/2 +"px";
          node.style.top = offsetT - node.offsetHeight/2 +"px";
          startMove();
        }
      },30)
    } 
    node.onmousedown = function(ev){
      var ev = ev || window.event;
      disX = ev.clientX - node.offsetLeft;
      disY = ev.clientY - node.offsetTop;

      preX = ev.clientX;//按下的点
      preY =  ev.clientY;
      clearInterval(timer)
    
      document.onmousemove = function(ev){
        var ev = ev || window.event;
          node.style.left = ev.clientX - disX + "px";
          node.style.top = ev.clientY - disY + "px";

          iSpeedX = ev.clientX - preX;//保证最后一个点与前一点的速度
          iSpeedY = ev.clientY - preY;

          preX = ev.clientX;
          preY =  ev.clientY;
        };
      document.onmouseup = function(){
        document.onmousemove = null; 
        document.onmouseup = null;
        startMove();  
      }
      return false;
    }
    
    function startMove(){
      
    clearInterval(timer);
    timer = setInterval(function(){
      iSpeedY += 3;

      var L = node.offsetLeft + iSpeedX;
      var T = node.offsetTop + iSpeedY ;
      if(L<0){
        L = 0;
        iSpeedX *= -1;
        iSpeedX *= 0.75;
      }else if(L>document.documentElement.clientWidth-node.offsetWidth){
        L = document.documentElement.clientWidth-node.offsetWidth;
        iSpeedX *= -1;
        iSpeedX *= 0.75;
      }
      if(T<0){
        T = 0;
        iSpeedY *= -1;
        iSpeedY *= 0.75;
      }else if(T>document.documentElement.clientHeight-node.offsetHeight){
        T = document.documentElement.clientHeight-node.offsetHeight;
        iSpeedY *= -1;
        iSpeedY *= 0.75;
        iSpeedX *= 0.75;
      }
      node.style.left = L +"px";
      node.style.top = T+"px";
    },30)
    }
  
   })
   $(window).scroll(function(){

   }) 
      
})